﻿/*-------------------------------------------------------------------------
* 命名空间: XrayDirection.Extensions/ImageExtensions
* 类       名: ImageExtensions
* 功      能:  图像处理相关的扩展方法
* 时      间:  2023/12/29 9:37:51
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using System.Drawing.Imaging;
using System.Windows.Media.Imaging;
using XrayDirection.ImageManager;

namespace XrayDirection.Extensions
{
    public static class ImageExtensions
    {
        /// <summary>
        /// 转换为ImageFormat类型,ImageDraw使用
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public static ImageFormat ToDrawingImageFormat(this ImageFormats format)
        {
            switch (format)
            {
                case ImageFormats.Jpg:
                    return ImageFormat.Jpeg;
                case ImageFormats.Png:
                    return ImageFormat.Png;
                case ImageFormats.Gif:
                    return ImageFormat.Gif;
                case ImageFormats.Bmp:
                    return ImageFormat.Bmp;
                default:
                    return ImageFormat.Png;
            }
        }

        public static BitmapEncoder ToBitmapEncoder(this ImageFormats format)
        {
            switch (format)
            {
                case ImageFormats.Jpg:
                    return new JpegBitmapEncoder();
                case ImageFormats.Png:
                    return new PngBitmapEncoder();
                case ImageFormats.Gif:
                    return new GifBitmapEncoder();
                case ImageFormats.Bmp:
                    return new BmpBitmapEncoder();
                default:
                    return new PngBitmapEncoder();
            }
        }
    }
}
